package com.jeesite.modules.formcategory.service;

import java.util.List;

import com.jeesite.common.lang.StringUtils;
import com.jeesite.common.service.ServiceException;
import com.jeesite.modules.common.vo.CommonSelectDataVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeesite.common.entity.Page;
import com.jeesite.common.service.TreeService;
import com.jeesite.modules.formcategory.entity.FormCategory;
import com.jeesite.modules.formcategory.dao.FormCategoryDao;

/**
 * 表单类别Service
 * @author 码脑洞
 * @version 2025-04-13
 */
@Service
public class FormCategoryService extends TreeService<FormCategoryDao, FormCategory> {
	
	/**
	 * 获取单条数据
	 * @param formCategory
	 * @return
	 */
	@Override
	public FormCategory get(FormCategory formCategory) {
		return super.get(formCategory);
	}
	
	/**
	 * 查询分页数据
	 * @param formCategory 查询条件
	 * @param formCategory page 分页对象
	 * @return
	 */
	@Override
	public Page<FormCategory> findPage(FormCategory formCategory) {
		return super.findPage(formCategory);
	}
	
	/**
	 * 查询列表数据
	 * @param formCategory
	 * @return
	 */
	@Override
	public List<FormCategory> findList(FormCategory formCategory) {
		return super.findList(formCategory);
	}
	
	/**
	 * 保存数据（插入或更新）
	 * @param formCategory
	 */
	@Override
	@Transactional
	public void save(FormCategory formCategory) {
		if (StringUtils.isBlank(formCategory.getCode())) {
			throw new ServiceException("编码不能为空");
		}

		// 检查编码唯一性
		FormCategory entity = dao.getFormCategory(formCategory);
		if (entity != null){
			throw new ServiceException("编码已存在，请重新输入");
		}
		super.save(formCategory);
	}
	
	/**
	 * 更新状态
	 * @param formCategory
	 */
	@Override
	@Transactional
	public void updateStatus(FormCategory formCategory) {
		super.updateStatus(formCategory);
	}
	
	/**
	 * 删除数据
	 * @param formCategory
	 */
	@Override
	@Transactional
	public void delete(FormCategory formCategory) {
		super.delete(formCategory);
	}
	
	/**
	 * 校验类别编码是否唯一
	 * @param formCategory 表单类别
	 * @return true-唯一 false-不唯一
	 */
	public FormCategory checkCodeUnique(FormCategory formCategory) {
		return dao.checkCodeUnique(formCategory);
	}

	public List<CommonSelectDataVO> selectFormCategoryList() {
		return dao.selectFormCategoryList();
	}
}